import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { LoginService } from 'app/modules/login/services/login.service';
import { ToasterService } from 'app/modules/share/services/toaster.service';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class CanActiveSuperAdmin implements CanActivate {

  constructor(
    private loginService: LoginService,
    private router: Router,
    private toaster: ToasterService) {}

  async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    const user = await this.loginService.User();
    console.log('is_super', user.is_super);
    if (!user.is_super) {
      this.toaster.warn('当前管理员无该功能模块权限');
      this.router.navigateByUrl('/');
    }
    return user.is_super;
  }
}
